/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package m;

/**
 *
 * @author Mikael Köhlmyr | mikael@kohlmyr.com | http://www.kmyr.net
 */
public class array {
    public static int[] add(int[] in, int addition){
        int[] out = new int[in.length + 1];
            for(int i = 0; i < in.length; i++){
                out[i] = in[i];
            }

        out[in.length] = addition;
        return out;
    }

    public static String[] add(String[] in, String addition){
        String[] out = new String[in.length + 1];
            for(int i = 0; i < in.length; i++){
                out[i] = in[i];
            }
        out[in.length] = addition;
        return out;
    }

    public static char[] add(char[] in, char addition){
        char[] out = new char[in.length + 1];
            for(int i = 0; i < in.length; i++){
                out[i] = in[i];
            }
        out[in.length] = addition;
        return out;
    }

    public static double[] add(double[] in, double addition){
        double[] out = new double[in.length + 1];
            for(int i = 0; i < in.length; i++){
                out[i] = in[i];
            }
        out[in.length] = addition;
        return out;
    }

    public static Object[] add(Object[] in, Object addition){
        Object[] out = new Object[in.length + 1];
            for(int i = 0; i < in.length; i++){
                out[i] = in[i];
            }
        out[in.length] = addition;
        return out;
    }

    public static int[] remove(int[] in, int index){
        int[] out = new int[in.length - 1];
        if((0 <= index) && (index < in.length)){
            for(int i = 0; i < in.length; i++){
                if(index > i){
                    out[i] = in[i];
                }
                if(index < i){
                    out[i-1] = in[i];
                }
            }
        }
        return out;
    }

    public static String[] remove(String[] in, int index){
        String[] out = new String[in.length - 1];
        if((0 <= index) && (index < in.length)){
            for(int i = 0; i < in.length; i++){
                if(index > i){
                    out[i] = in[i];
                }
                if(index < i){
                    out[i-1] = in[i];
                }
            }
        }
        return out;
    }

    public static int[] removeAll(int[] in, int value){
        int k = 0;
        for(int i = 0; i < in.length; i++){
            if(in[i] == value){
                k++;
            }
        }
        int[] out = new int[in.length - k];
        int modifier = 0;
        for(int j = 0; j < out.length; j++){
            if(in[j + modifier] != value){
                out[j] = in[j + modifier];
            }
            else{
                modifier++;
            }
        }
        return out;
    }

    public static String[] removeAll(String[] in, String value){
        int k = 0;
        for(int i = 0; i < in.length; i++){
            if(in[i].equals(value)){
                k++;
            }
        }
        String[] out = new String[in.length - k];
        int modifier = 0;
        for(int j = 0; j < out.length; j++){
            if(!in[j + modifier].equals(value)){
                out[j] = in[j + modifier];
            }
            else{
                modifier++;
            }
        }
        return out;
    }

    public static int[] attach(int[] a, int[] b){
        int[] out = new int[a.length + b.length];
        for(int i = 0; i < out.length; i++){
            if(i < a.length){
                out[i] = a[i];
            }
            else{
                out[i] = b[i - a.length];//might be off by 1.. tired
            }
        }
        return out;
    }

    public static String[] attach(String[] a, String[] b){
        String[] out = new String[a.length + b.length];
        for(int i = 0; i < out.length; i++){
            if(i < a.length){
                out[i] = a[i];
            }
            else{
                out[i] = b[i - a.length];//might be off by 1.. tired
            }
        }
        return out;
    }

    public static String toStr(int[] in){
        String out = "";
        for(int i = 0; i < in.length; i++){
            out.concat(lang.toStr(in[i]));
        }
        return out;
    }

    public static String toStr(String[] in){
        String out = "";
        for(int i = 0; i < in.length; i++){
            out.concat(in[i]);
        }
        return out;
    }

    public static String toStr(char[] in){
        String out = "";
        for(int i = 0; i < in.length; i++){
            out.concat(lang.toStr(in[i]));
        }
        return out;
    }

    public static int[] nullify(int[] in){
        for(int i = 0; i < in.length; i++){
            Integer empty = null;
            in[i] = empty.intValue();
        }
        return in;
    }

    public static String[] nullify(String[] in){
        for(int i = 0; i < in.length; i++){
            in[i] = null;
        }
        return in;
    }

    public static boolean isNull(int[] in){
        boolean notNull = false;
        Integer temp;
        for(int i = 0; i < in.length; i++){
            temp = in[i];
            if(temp != null){
                notNull = true;
            }
        }
        return lang.inverse(notNull);
    }

    public static boolean isNull(String[] in){
        boolean notNull = false;
        for(int i = 0; i < in.length; i++){
            if(in[i] != null){
                notNull = true;
            }
        }
        return lang.inverse(notNull);
    }

    public static boolean tautology(boolean[] in){
        for(int i = 0; i < in.length; i++){
            if(in[i] == false){
                return false;
            }
        }
        return true;
    }
    // write a version for twodimensional arrays (boolean[][]) as well

    public static boolean contradiction(boolean[] in){
        return lang.inverse(tautology(in));
    }
}